<%--
  Created by IntelliJ IDEA.
  User: GZ
  Date: 2021/7/8
  Time: 20:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改视频分类</title>
    <script src="/js/jquery/jquery-3.3.1.js"></script>
    <script>
        $(function () {

            $.ajax({
                url: '/sort/load_by_id',
                type: 'get',
                data: {id:${param.id}},
                dataType: 'json',
                success: function (jsonData) {
                    var sort = jsonData.sort;
                    if($.isEmptyObject(sort))
                    {
                        alert('未查询到视频分类数据');
                        $('form').remove();
                        return;
                    }
                    $(':text[name="type"]').val(sort.type);
                    var level = sort.level;
                    if (1 == level) {
                        $('#level-li').append('一级');
                        $('#p-type-li').remove();
                        return;
                    }
                    if (2 != level) {
                        alert('视频分类级别错误!!');
                        return;
                    }
                    $('#level-li').append('二级');
                    var sortList=jsonData.sortList;
                    var len = sortList.length;
                    for (var index = 0; index < len; index++) {
                        var s = sortList[index];
                        var id = s.id;
                        var type = s.type;
                        //构建一个option选项
                        var optionHTML = '<option value="' + id + '">' + type + '</option>';
                        $('#p-type-select').append(optionHTML);
                    }
                    //选中父分类
                    var pId=sort.pId;
                    $('#p-type-select').val(pId);
                },
                error: function () {
                    alert('加载视频一级分类数据失败!!!');
                }

            });
        });
        function modifySort()
        {
            if('确定修改视频分类吗?')
            {
               $('form').submit();
            }
        }
    </script>
</head>
<body>
<form action="/sort/modify" method="post">
    <ul style="list-style: none">
        <li><h3>修改视频分类</h3></li>
        <li><span>分类名称:</span><input type="text" name="type"></li>
        <li id="level-li"><span>分类等级:</span>
        </li>
        <li id="p-type-li"><span>所属父分类:</span>
            <select id="p-type-select" name="pId">
                <option disabled>----所属一级分类---</option>
            </select>
        </li>
        <li>
            <button type="button" onclick="modifySort()">修改分类</button>
            <input type="hidden" name="id" value="${param.id}">
            <button type="reset">重新填写</button>
        </li>
    </ul>
</form>
</body>
</html>
